package ar.com.ford.it.fullEconomics.view.action;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import ar.com.ford.it.fullEconomics.FullEconomicsPrs;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.facade.CurrencyFacade;
import ar.com.ford.it.fullEconomics.facade.EconomicIndexDefFacade;
import ar.com.ford.it.fullEconomics.facade.EconomicSourceFacade;
import ar.com.ford.it.fullEconomics.facade.EconomicValueFacade;
import ar.com.ford.it.fullEconomics.persistence.dto.Teese01Economic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teese03Econvalue;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesm01Currency;
import ar.com.ford.it.fullEconomics.struct.EconomicValueStruct;
import ar.com.ford.it.fullEconomics.struct.OptionCombo;
import ar.com.ford.it.fullEconomics.util.FullEconomicsDateUtil;
import ar.com.ford.it.fullEconomics.view.form.EconomicValueForm;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;
import ar.com.ford.it.webengine.facade.FacadeProvider;
import ar.com.ford.it.webengine.struts.AbstractBaseAction;
import ar.com.ford.it.webengine.struts.FordActionMapping;
import ar.com.ford.it.webengine.websession.WebSession;

public class EconomicValueAction extends AbstractBaseAction {

    @Override
    /**
     * Init muestra la pantalla sin el listado
     */
    public ActionForward initPage(FordActionMapping mapping,
                                  ActionForm actionForm,
                                  HttpServletRequest request,
                                  HttpServletResponse response,
                                  WebSession webSession, ActionMessages msgs,
                                  ActionMessages warns, ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        form.resetForm();
        form.setEconomicValues(null);

        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        form.resetForm();
        EconomicSourceFacade facadeSour = (EconomicSourceFacade) FacadeProvider
                .getFacade(request, EconomicSourceFacade.class);
        EconomicValueFacade facadeValue = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        try {
            // Combo Sour
            form.setEconomicSour(facadeSour.findEconomicSources(null, null,
                    user.getTeesg01Plant()));
            // Combo Periodos
            request.getSession().setAttribute("months",
                    FullEconomicsDateUtil.getComboMonths());
            request.getSession().setAttribute(
                    "economicSources",
                    facadeSour.findEconomicSources(null, null, user
                            .getTeesg01Plant()));
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
            // Combo tpype Economics
            Collection<OptionCombo> ecoType = new ArrayList<OptionCombo>();
            OptionCombo actual = new OptionCombo("A", "Actual");
            ecoType.add(actual);
            OptionCombo forcasted = new OptionCombo("F", "Futuro");
            if (user.getPermissions().contains("PERM_F")) {
                ecoType.add(forcasted);
            }
            request.getSession().setAttribute("economicsTypes", ecoType);

            // Combo valor estimado
            Collection<OptionCombo> ecoValEstimado = new ArrayList<OptionCombo>();
            OptionCombo vYes = new OptionCombo("1", "Si");
            OptionCombo vNo = new OptionCombo("0", "No");
            ecoValEstimado.add(vYes);
            ecoValEstimado.add(vNo);
            request.getSession().setAttribute("economicsEstimate",
                    ecoValEstimado);

        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }

        return mapping.findForward("success");
    }

    /**
     * Crea o actualiza el economic Value
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward createUpdateEconomicValue(
                                                   FordActionMapping mapping,
                                                   ActionForm actionForm,
                                                   HttpServletRequest request,
                                                   HttpServletResponse response,
                                                   WebSession webSession,
                                                   ActionMessages msgs,
                                                   ActionMessages warns,
                                                   ActionMessages errorMsgs) {
        ActionMessages am = new ActionMessages();
        Teese03Econvalue ecoV = new Teese03Econvalue();
        Teesm01Currency curren = new Teesm01Currency();
        Teese01Economic econ = new Teese01Economic();
        EconomicValueForm form = (EconomicValueForm) actionForm;
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        EconomicValueFacade facadeValueE = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        try {
            Calendar fechaEfe = FullEconomicsDateUtil.format(form.getEfecEco());
            Timestamp auxFecha = new Timestamp(fechaEfe.getTimeInMillis());
            validateDateByPerm(auxFecha, user.getPermissions());
            // Seteo las claves de los obj asociados a mi economic value
            curren.setEesm01CurrencyCodeC(form.getCurrEcon());
            econ.setEese01EconNumberK(Integer.valueOf(form.getCodeEcon()));
            // Formateo de fecha in
            ecoV.setEese03CurrencyCodeC(curren);
            ecoV.setTeese01Economic(econ);
            ecoV.setEese03PlantCodeC(user.getTeesg01Plant());
            ecoV.setEese03EcvalueEffectivDateY(auxFecha);
            ecoV.setEese03EcvalueTypeCodeC(form.getTypeCodeEco());
            if (StringUtils.isEmpty(form.getTypeCodeEco())) {
                ecoV.setEese03EcvalueTypeCodeC(form.getEconomicValue()
                        .getEese03EcvalueTypeCodeC());
            }
            // Indicador si el valor estimado cambio
            ecoV.setEese03EcvalueEstimateFlagF(form.getEcoStimateF());
            if (StringUtils.isEmpty(form.getEcoStimateF())) {
                // En el caso de una modificacion elijo seteo si cambio el valor
                // estiamdo
                ecoV.setEese03EcvalueEstimateFlagF(form.getEconomicValue()
                        .getEese03EcvalueEstimateFlagF());
            }

            boolean isRepeat = facadeValueE.economicValueIsRepeat(ecoV);

            // Logica de update o Create
            if (form.getSection().equals("edit") && isRepeat) {
                // Realizar Actualizar
                if (!StringUtils.isEmpty(form.getPorcEco())) {
                    ecoV.setEese03EcvalueVariaPercentP(BigDecimal
                            .valueOf(Double.valueOf(form.getPorcEco())));
                    BigDecimal value = form.getPrevEconValue()
                            .getEese03EcvalueAmountA().multiply(
                                    new BigDecimal(1).add(ecoV
                                            .getEese03EcvalueVariaPercentP()
                                            .divide(new BigDecimal(100))));
                    ecoV.setEese03EcvalueAmountA(value);
                } else {
                    if (form.getPrevEconValue() != null
                            && form.getPrevEconValue()
                                    .getEese03EcvalueAmountA() != null) {
                        BigDecimal percIncr = new BigDecimal(form.getValEco())
                                .subtract(
                                        form.getPrevEconValue()
                                                .getEese03EcvalueAmountA())
                                .divide(
                                        form.getPrevEconValue()
                                                .getEese03EcvalueAmountA(), 5,
                                        BigDecimal.ROUND_HALF_EVEN).multiply(
                                        new BigDecimal(100));
                        ecoV.setEese03EcvalueVariaPercentP(percIncr);
                    }
                    ecoV.setEese03EcvalueAmountA(new BigDecimal(form
                            .getValEco()));

                }
                facadeValueE.economicValueUpdate(ecoV, user);
            }
            if (form.getSection().equals("new") || !isRepeat) {
                ecoV.setEese03EcvalueAmountA(BigDecimal.valueOf(Double
                        .valueOf(form.getValEco())));
                facadeValueE.economicValueCreate(ecoV, user);
            }
        } catch (FullEconomicsException e) {
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        form.resetPanel();
        return mapping.findForward("success");
    }

    private void validateDateByPerm(Timestamp auxFecha, List list)
            throws FullEconomicsException {
        Timestamp fechaA = new Timestamp(System.currentTimeMillis());

        if (auxFecha.after(fechaA) && !list.contains("PERM_F")) {
            Exception e = null;
            throw new FullEconomicsException(e,
                    FullEconomicsPrs.MessageErrors.EconomicValue.PERM);
        }

    }

    /**
     * Eliminca el Economic Value
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward deleteEconomicVaue(FordActionMapping mapping,
                                            ActionForm actionForm,
                                            HttpServletRequest request,
                                            HttpServletResponse response,
                                            WebSession webSession,
                                            ActionMessages msgs,
                                            ActionMessages warns,
                                            ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        EconomicValueFacade facade = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        Teese03Econvalue ecoV = new Teese03Econvalue();
        form.economicValuesMapped(form.getNumberEconomicValue(), "");
        ecoV = form.getEconomicValue();
        try {
            facade.economicValueDelete(ecoV, user);

        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }

    /**
     * setea los parametros en el panel de trabajo para la busqueda o creacion
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward editSetEconomicValue(FordActionMapping mapping,
                                              ActionForm actionForm,
                                              HttpServletRequest request,
                                              HttpServletResponse response,
                                              WebSession webSession,
                                              ActionMessages msgs,
                                              ActionMessages warns,
                                              ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        form.economicValuesMapped(form.getNumberEconomicValue(), "");
        form.setEditParametersPanel();

        return mapping.findForward("success");
    }

    /**
     * Deshace la creacion o modificacion del valor del indice economico
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward clearEconomicValue(FordActionMapping mapping,
                                            ActionForm actionForm,
                                            HttpServletRequest request,
                                            HttpServletResponse response,
                                            WebSession webSession,
                                            ActionMessages msgs,
                                            ActionMessages warns,
                                            ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        form.resetPanel();
        form.setOperation("");
        return mapping.findForward("success");
    }

    /**
     * Setea en el panel de edicion los datos del indice para darlo de alta
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward newSetEconomicValue(FordActionMapping mapping,
                                             ActionForm actionForm,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             WebSession webSession,
                                             ActionMessages msgs,
                                             ActionMessages warns,
                                             ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        form.setNewParametersPanel();
        return mapping.findForward("success");
    }

    /**
     * Aprueba el valor del indice economico
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward approveEconomicValue(FordActionMapping mapping,
                                              ActionForm actionForm,
                                              HttpServletRequest request,
                                              HttpServletResponse response,
                                              WebSession webSession,
                                              ActionMessages msgs,
                                              ActionMessages warns,
                                              ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;

        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        EconomicValueFacade facade = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        Teese03Econvalue ecoV = form.getEconomicValue();
        try {
            if (facade.validateAppro(ecoV, user)) {
                facade.approEconomicValue(ecoV, user);
            } else {
                ActionMessages am = new ActionMessages();
                am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                        "economicValue.error.approve"));
                saveErrors(request, am);
            }
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }

    @SuppressWarnings("unchecked")
    /**
     * Busca los indices economcios segun los filtros
     */
    public ActionForward findEconomicValue(FordActionMapping mapping,
                                           ActionForm actionForm,
                                           HttpServletRequest request,
                                           HttpServletResponse response,
                                           WebSession webSession,
                                           ActionMessages msgs,
                                           ActionMessages warns,
                                           ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;

        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        EconomicIndexDefFacade facadeEco = (EconomicIndexDefFacade) FacadeProvider
                .getFacade(request, EconomicIndexDefFacade.class);
        EconomicValueFacade facadeVal = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        Collection<EconomicValueStruct> screenList = new ArrayList<EconomicValueStruct>();
        EconomicValueStruct findEconomicVal = null;
        Teese03Econvalue auxEco;
        // Search de los indices economicos que correspondan con sel source el
        // codigo o descripcion
        String anio = form.getEfectYear();
        String mes = form.getEfectMonth();
        String fecha = "01/" + mes + "/" + anio;

        Calendar efecDate = FullEconomicsDateUtil.format(fecha);

        Timestamp efectiveDate = new Timestamp(efecDate.getTimeInMillis());
        @SuppressWarnings("unused")
        Timestamp auxFecha;
        String tipoR = form.getFilterEstatus();
        if (tipoR.equals(""))
            tipoR = null;
        String tipoC = form.getTypeFind();

        try {
            Collection<Teese01Economic> ecoIndex = facadeEco
                    .findEconomicIndexDef(form.getCodeFind(), form
                            .getDescFind(), form.getSourcFind(), user
                            .getTeesg01Plant());

            if (!ecoIndex.isEmpty()) {
                for (Teese01Economic economicIndex : ecoIndex) {
                    auxEco = new Teese03Econvalue();
                    auxFecha = new Timestamp(0);
                    auxEco.setTeese01Economic(economicIndex);
                    auxEco.setEese03CreateUserC(tipoR);
                    auxEco.setEese03EcvalueTypeCodeC(tipoC);
                    auxEco.setEese03EcvalueEffectivDateY(efectiveDate);
                    auxEco.setEese03PlantCodeC(user.getTeesg01Plant());
                    Timestamp periodSelec = efectiveDate;
                    findEconomicVal = new EconomicValueStruct();
                    if (facadeVal.isRegisterEconomic(auxEco)) {
                        if (!form.getFilterEstatus().equals("noRegistrados")) {
                            // Busqueda de Indice economico menor a la fecha
                            // dada en el periodo de actualizacion del indice
                            // economico
                            Collection getEcoVMLD = facadeVal
                                    .getEconomicValuesMaxPeriodDate(auxEco);

                            if (!getEcoVMLD.isEmpty()) {
                                // Busqueda de economic Value anterior a la
                                // ultima fecha efectiva
                                findEconomicVal
                                        .setEconomicValueActual((Teese03Econvalue) getEcoVMLD
                                                .iterator().next());
                                auxEco.setEese03EcvalueEffectivDateY(sumaDias(
                                        auxEco.getEese03EcvalueEffectivDateY(),
                                        -1));
                                Collection getEcoVMLAnteriorPeriodo = facadeVal
                                        .getEconomicValuesMaxLessDate(
                                                auxEco,
                                                sumaDias(
                                                        ((Teese03Econvalue) getEcoVMLD
                                                                .iterator()
                                                                .next())
                                                                .getEese03EcvalueEffectivDateY(),
                                                        -1));
                                if (!getEcoVMLAnteriorPeriodo.isEmpty())
                                    findEconomicVal
                                            .setEconomicValuePasado((Teese03Econvalue) getEcoVMLAnteriorPeriodo
                                                    .iterator().next());
                                screenList.add(findEconomicVal);

                            }

                            if (getEcoVMLD.isEmpty()
                                    && !(form.getFilterEstatus().equals(
                                            "registrados") || form
                                            .getFilterEstatus().equals(
                                                    "aprobados"))) {
                                // Busqueda de Indice economico menor a la fecha
                                // dada
                                screenList.add(createListEcvaEconvalue(auxEco
                                        .getTeese01Economic()));
                                /*
                                 * if (!getEcoVMLessDate.isEmpty()) { //
                                 * Busqueda de economic Value anterior a la //
                                 * ultima fecha efectiva findEconomicVal
                                 * .setEconomicValueActual((Teese03Econvalue)
                                 * getEcoVMLessDate .iterator().next()); auxEco
                                 * .setEese03EcvalueEffectivDateY(sumaDias(
                                 * auxEco .getEese03EcvalueEffectivDateY(),
                                 * -1)); Collection getEcoVMLALess = facadeVal
                                 * .getEconomicValuesMaxLessDate( auxEco,
                                 * sumaDias( ((Teese03Econvalue)
                                 * getEcoVMLessDate .iterator() .next())
                                 * .getEese03EcvalueEffectivDateY(), -1)); if
                                 * (!getEcoVMLALess.isEmpty()) findEconomicVal
                                 * .setEconomicValuePasado((Teese03Econvalue)
                                 * getEcoVMLALess .iterator().next());
                                 * screenList.add(findEconomicVal); }
                                 */
                            }

                            // Registro el indice economico si no se encontraron
                            // en la busquedas anteriores
                            // esto indica qeu es un valor forcasted

                        }
                    } else {
                        if (!form.getFilterEstatus().equals("registrados")
                                && !form.getFilterEstatus().equals("aprobados"))
                            screenList
                                    .add(createListEcvaEconvalue(economicIndex));

                    }

                }

            }
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        // Oculto el panel de edicion
        form.setOperation("");
        // Muestro la ultima busqueda realizada
        form.setEconomicValues(screenList);
        if (screenList.isEmpty())
            searchWithNoResults(request);
        return mapping.findForward("success");
    }

    private EconomicValueStruct createListEcvaEconvalue(Teese01Economic ecoI) {
        EconomicValueStruct ecoS = new EconomicValueStruct();
        Teese03Econvalue ecoV = new Teese03Econvalue();
        ecoV.setTeese01Economic(ecoI);
        ecoV.setEese03CurrencyCodeC(ecoI.getEese01CurrencyCodeC());
        ecoS.setEconomicValueActual(ecoV);
        return ecoS;
    }

    public static Timestamp sumaDias(Timestamp fch, int dias) {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(fch.getTime());
        cal.add(Calendar.DATE, dias);
        return (Timestamp) new Timestamp(cal.getTimeInMillis());
    }

    public static Timestamp sumaMes(Timestamp fch, int meses) {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(fch.getTime());
        cal.add(Calendar.MONTH, meses);
        return (Timestamp) new Timestamp(cal.getTimeInMillis());
    }

    /**
     * Conexion entre Economic Index Status && Economic Values Seteo de valores,
     * los cuales me serviran para poder operar en la siguiente pantalla
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward findEconomicValueByStatus(
                                                   FordActionMapping mapping,
                                                   ActionForm actionForm,
                                                   HttpServletRequest request,
                                                   HttpServletResponse response,
                                                   WebSession webSession,
                                                   ActionMessages msgs,
                                                   ActionMessages warns,
                                                   ActionMessages errorMsgs) {
        EconomicValueForm form = (EconomicValueForm) actionForm;
        form.setSection("find");
        EconomicSourceFacade facadeSour = (EconomicSourceFacade) FacadeProvider
                .getFacade(request, EconomicSourceFacade.class);
        EconomicValueFacade facadeValue = (EconomicValueFacade) FacadeProvider
                .getFacade(request, EconomicValueFacade.class);
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        String anio = request.getAttribute("econSourceStatusDate").toString()
                .substring(6, 10);
        String mes = request.getAttribute("econSourceStatusDate").toString()
                .substring(3, 5);
        String typeEcon = request.getAttribute("econTypeEconomic").toString()
                .trim();
        form.setEfectYear(anio);
        form.setEfectMonth(mes);
        form.setFilterEstatus("todos");
        form.setTypeFind(typeEcon);
        form.setSourcFind(request.getAttribute("econSourceStatusNumber")
                .toString());
        form.setEconomicValues(null);
        Collection<OptionCombo> ecoType = new ArrayList<OptionCombo>();
        OptionCombo actual = new OptionCombo("A", "Actual");
        ecoType.add(actual);
        OptionCombo forcasted = new OptionCombo("F", "Forcasted");
        if (user.getPermissions().contains("PERM_F")) {
            ecoType.add(forcasted);
        }
        Collection<OptionCombo> ecoValEstimado = new ArrayList<OptionCombo>();
        OptionCombo vYes = new OptionCombo("1", "Si");
        OptionCombo vNo = new OptionCombo("0", "No");
        ecoValEstimado.add(vYes);
        ecoValEstimado.add(vNo);

        try {
            form.setEconomicSour(facadeSour.findEconomicSources(null, null,
                    user.getTeesg01Plant()));
            form.setEconomicEfec(facadeValue.economicValuePeriods(user
                    .getTeesg01Plant()));
            request.getSession().setAttribute("months",
                    FullEconomicsDateUtil.getComboMonths());
            request.getSession().setAttribute(
                    "economicSources",
                    facadeSour.findEconomicSources(null, null, user
                            .getTeesg01Plant()));
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
            request.getSession().setAttribute("economicsTypes", ecoType);
            request.getSession().setAttribute("economicsEstimate",
                    ecoValEstimado);

        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }

    /**
     * Envia email cuando re rechaza un valor de indice economico
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward rejectEconomicValue(FordActionMapping mapping,
                                             ActionForm actionForm,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             WebSession webSession,
                                             ActionMessages msgs,
                                             ActionMessages warns,
                                             ActionMessages errorMsgs) {
        @SuppressWarnings("unused")
        EconomicValueForm form = (EconomicValueForm) actionForm;
        return mapping.findForward("success");
    }

    /**
     * Setea el mensaje de "busqueda sin resultados" cuando la busqueda no trae
     * resultados
     * 
     * @param request
     * Request donde se guarda el mensaje
     */
    private void searchWithNoResults(HttpServletRequest request) {
        ActionMessages am = new ActionMessages();
        MessageResources messageResources = (MessageResources) getResources(request);

        am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "customMessage", messageResources
                        .getMessage("message.noResults")));
        saveMessages(request, am);
    }
}
